﻿using System;
using System.Data.SqlClient;
using Devv.Core.UniDataTier;
using Yglu.BusinessLayer.Entities;

namespace Yglu.BusinessLayer
{
	public partial class DataAccess
	{
		#region Main reports

		public static SqlDataReader Report_StoreOrders(Int32 id, Period period)
		{
			DataHandler db = new DataHandler();

			db.AddParameter("@StoreId", id);

			if (period != null)
			{
				db.AddParameter("@DateFrom", period.DateFrom);
				db.AddParameter("@DateTo", period.DateTo);
			}
            
			return (SqlDataReader)db.ExecuteReader("upReport_StoreOrders");
		}

		public static SqlDataReader Report_UserOrders(Int32 id, Store store, Period period)
		{
			DataHandler db = new DataHandler();

			db.AddParameter("@UserId", id);

			if (period != null)
			{
				db.AddParameter("@DateFrom", period.DateFrom);
				db.AddParameter("@DateTo", period.DateTo);
			}

			if (store != null && store.Id > 0)
			{
				db.AddParameter("@StoreId", id);
			}

			return (SqlDataReader)db.ExecuteReader("upReport_UserOrders");
		}

		public static SqlDataReader Report_ProductOrders(Int32 id, Store store, Period period)
		{
			DataHandler db = new DataHandler();

			db.AddParameter("@ProductId", id);

			if (period != null)
			{
				db.AddParameter("@DateFrom", period.DateFrom);
				db.AddParameter("@DateTo", period.DateTo);
			}

			if (store != null && store.Id > 0)
			{
				db.AddParameter("@StoreId", id);
			}

			return (SqlDataReader)db.ExecuteReader("upReport_ProductOrders");
		}

		public static SqlDataReader Report_PromotionUsage(Int32 id, Store store, Period period)
		{
			DataHandler db = new DataHandler();

			db.AddParameter("@PromotionId", id);

			if (period != null)
			{
				db.AddParameter("@DateFrom", period.DateFrom);
				db.AddParameter("@DateTo", period.DateTo);
			}

			if (store != null && store.Id > 0)
			{
				db.AddParameter("@StoreId", id);
			}

			return (SqlDataReader)db.ExecuteReader("upReport_PromotionUsage");
		}

		#endregion
	}
}